package com.linc.android.app;

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.util.Log;

public class WidgetDemoApplication {
    private static final String TAG = "WidgetDemoApplication";
    private List<Activity> mActivityList = new LinkedList<Activity>();
    
    private static WidgetDemoApplication instance;
    public static WidgetDemoApplication getInstance() {
        if(instance == null)
            instance = new WidgetDemoApplication();
        return instance;
    }
    
    public void addActivity(Activity activity) {
        Log.d(TAG,"add activity: "+activity.getLocalClassName());
        mActivityList.add(activity);
    }
    
    public void removeActivity(Activity activity) {
        Log.d(TAG,"remove activity: "+activity.getLocalClassName());
        mActivityList.remove(activity);
    }
    
    public void exit() {
        try {
            for(Activity activity:mActivityList) {
                if(activity != null) {
                    Log.d(TAG,"finish activity: "+activity.getLocalClassName());            
                    activity.finish();
                }
            }
        } catch(Exception ex) {
            Log.e("ActivityManager",ex.getMessage());
        } finally {
            System.exit(0);
        }
    }
}
